﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace StatusPlan3.UC
{
    /// <summary>
    /// Interaction logic for UCMessages.xaml
    /// </summary>
    public partial class UCMessages : UserControl
    {
        public Messages messages;
        public UCTask task;
        public Issue issue;
        public UCTasks project;
        public Subproject subproject;

        public UCMessages()
        {
            InitializeComponent();
        }

        public UCMessages(Messages m)
        {
            InitializeComponent();
            setData(m);
        }

        public void setData(Messages orgM)
        {
            messages = orgM;
            if (messages.Count > 0)
            {
                var messagesOrderdByDate = (from m2 in messages orderby m2.createdDate descending select m2);

                foreach (Message m in messagesOrderdByDate)
                {
                    UC.UCMessageWithReply blah = new UC.UCMessageWithReply(m, this);
                    ContentStackPane.Children.Add(blah);
                }
            }

            UC.UCMessage newMessage = new UC.UCMessage();
            newMessage.ucMessages = this;
            newMessage.isNewMessage();
            newMessage.Visibility = System.Windows.Visibility.Collapsed;
            StackPanel_newMesage.Children.Add(newMessage);
        }

        private void RadButton_Click(object sender, RoutedEventArgs e)
        {
            foreach (UIElement uie in StackPanel_newMesage.Children)
                if (uie.Visibility != System.Windows.Visibility.Visible)
                    uie.Visibility = System.Windows.Visibility.Visible;
        }
    }
}
